<?php
// +---------------------------------------------------------------------------+
// | This file is part of the KnowledgebasePublisher package                   |
// | KnowledgebasePublisher - web based knowledgebase publisher tool           |
// |                                                                           |
// | Author:  Evgeny Leontev <eleontev@gmail.com>                              |
// | Copyright (c) 2005 Evgeny Leontev                                         |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

class KBGlossaryModel extends AppModel
{
	var $tbl_pref_custom = 'kb_';
	var $tables = array('table'=>'glossary', 'glossary');
	
	

	function getRecordsSql() { 
	
		$sql = "SELECT * FROM {$this->tbl->table}
		WHERE {$this->sql_params}
		{$this->sql_params_order}";
		
		//echo "<pre>"; print_r($sql); echo "</pre>";
		return $sql;
	}		
	

	function status($value, $id) {
		$sql = "UPDATE {$this->tbl->table} SET display_once='%s' WHERE id IN (%s)";
		$sql = sprintf($sql, mysql_escape_string($value), $this->idToString($id));
		$this->db->Execute($sql) or die(db_error($sql));
	}
	
	
	function &getAltPhrases($ids) {
		$data = array();
		$sql = "SELECT * FROM {$this->tbl->table}_alt WHERE glossary_id IN ($ids)";		
		$result =& $this->db->Execute($sql) or die(db_error($sql));
		
		while($row =& $result->FetchRow()){
			$data[$row['glossary_id']][] = $row['phrase'];
		}
		
		return $data;
	}
	
	
//	function getCountRecordsSql() {
//		$sql = "SELECT * FROM {$this->tbl->table} WHERE {$this->sql_params}";
//	}
	
	
	
	// SEARCH & REPLACE // ---------------------
	
	
	
	// ACTIONS // ---------------------
	

	
	
	
	
	// DELETE RELATED // ---------------------


}



/*
	// try to return all records mean main word and alt words
	function &getRecords($limit = -1, $offset = -1) {
		
		$sql = "SELECT g.phrase, g.definition, g.id, ga.phrase AS alt_phrase
		FROM {$this->tbl->glossary} g 
		LEFT JOIN {$this->tbl->glossary}_alt ga ON g.id = ga.glossary_id";
		
		
		if($limit == -1) {
			$result =& $this->db->Execute($sql) or die(db_error($sql));
		} else {
			$result =& $this->db->SelectLimit($sql, $limit, $offset) or die(db_error($sql));
		}
		
		$id = false; $j = 0;
		while($row = $result->FetchRow()){
			
			// go to second time
			if($id == $row['id']) {
				$result->Move($j);
				$id = false;
			}
			
			$data['main'][$row['id']] = $row;
			if($row['alt_phrase']) {
				$data['alt'][$row['id']][$row['alt_phrase']] = $j;
				//$data['alt'][$row['id']][] = $row['alt_phrase'];
				
			}
			
			$id = $row['id'];
			$j++;
		}
		
		
		//$data['alt'] = array_reverse($data['alt']);
		//echo "<pre>"; print_r($data); echo "</pre>";
		return $data;
	}
*/
?>
